package com.n5x.model.admin;

import com.n5x.common.util.CipherHashUtil;
import com.n5x.model.AbstractModel;

public class AdminUser extends AbstractModel {

    public static final String LOGIN_PASS_SALT = "admin_n5x";

    public enum Type {
        超级管理员, 后台管理员, 收银员, 送货员;

        public static AdminUser.Type getType(Integer ordinal) {
            if (ordinal == null) return null;
            int size = Type.values().length;
            if (ordinal < 0 || ordinal > size - 1) return null;
            return AdminUser.Type.values()[ordinal];
        }

        public static int indexOf(String typeName){
            for (int i = 0 ;i < Type.values().length ;i++){
                Type type = Type.values()[i];
                if(type.name().equals(typeName)){
                    return  i ;
                }
            }
            return  -1;
        }
    }

    /**
     * 编制密码
     *
     * @param password 密码
     * @return
     */
    public static String encodePassword(String password) {
        return CipherHashUtil.initHashService(password, LOGIN_PASS_SALT).computeHash();
    }

    private String loginName;

    private String password;

    private String type;

    private String fullName;

    public String getLoginName() {
        return loginName;
    }

    public void setLoginName(String loginName) {
        this.loginName = loginName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = AdminUser.encodePassword(password);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFullName() {
        return fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

}